<template>
  <!--开票审请-->
  <BasicModal title="选择业务流水" :width="500" :height="800" :canFullscreen="false" :centered="true"
              :destroyOnClose="true" @register="registerModal" @ok="handleSubmit"
  >
    <a-form ref="registerForm" :model="model" :labelCol="{ span: 6 }" :wrapperCol="{ span: 16 }">
      <a-form-item label="单位名称" :wrapperCol="{ span: 16 }">
        {{model.dwmc}}
      </a-form-item>

      <a-form-item label="收支类型" name="number" :wrapperCol="{ span: 16 }">
        {{model.zwsflx}}
      </a-form-item>

      <a-form-item label="收支笔数" :wrapperCol="{ span: 16 }">
        {{model.counts}}
      </a-form-item>

      <a-form-item label="付款金额" :wrapperCol="{ span: 16 }">
        {{model.je}}
      </a-form-item>

      <a-form-item label="备注" :wrapperCol="{ span: 16 }">
        <a-input type="text" v-model:value="model.bz"></a-input>
      </a-form-item>

    </a-form>
  </BasicModal>
</template>

<script lang="ts" setup>
import { ref, computed, unref, reactive } from "vue";
import { BasicModal, useModalInner } from "/@/components/Modal";
import { useMessage } from "/@/hooks/web/useMessage";
import { openAccountGridSelectModal, openAccountGridSelectSubmit } from "/@/views/full/invoice/types/invoice.api";

const isUpdate = ref(true);
const { createMessage: $message } = useMessage();

const emit = defineEmits(['success', 'register']);
const $businessId = ref("");
//表单modal
let model = reactive<any>({})

//表单赋值
const [registerModal, { closeModal }] = useModalInner(async (data) => {
  $businessId.value = data.businessId
  let params = {ids: data.ids, type: data.type}
  await openAccountGridSelectModal(params).then((res) => {
    try {
      if (res.success != true) {
        $message.warning(res.message);
        return false;
      }
      let result = res.result;
      //1、业务数据 - 初始化
      Object.assign(model, result);

    } catch (e) {
      alert(e);
      return false;
    }
  }).finally(() => {

  });
});

async function handleSubmit() {
  let params = {
    'account_ids': model.account_ids,  //主要参数
    'bz' : model.bz,
    'sflx' : model.sflx,
    'businessId' : $businessId.value,
  }
  await openAccountGridSelectSubmit(params).then((res) => {
    try {
      if (res.success != true) {
        $message.warning(res.message);
        return false;
      } else {
        $message.success("操作成功！");
        closeModal();
        emit("success");
      }
    } catch (e) {
      alert(e);
      return false;
    }
  })
}

</script>

<style lang="less" scoped>

</style>
